package com.example.miaosha.miaosha_20220302.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.miaosha.miaosha_20220302.entity.Sku;
import com.example.miaosha.miaosha_20220302.mapper.SkuMapper;
import com.example.miaosha.miaosha_20220302.service.SkuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cxw
 * @since 2022-03-02
 */
@Service
public class SkuServiceImpl extends ServiceImpl<SkuMapper, Sku> implements SkuService {

    @Override
    public Sku reduceNum(Integer reduceNum, Integer skuId) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("skuId",skuId);
        map.put("reduceNum",reduceNum);

        int i = this.baseMapper.updateSku(map);

        Sku sku = new Sku();
        sku.setSkuId(skuId);
        if (i>0){
            return sku;
        }

        throw new RuntimeException("扣减失败");
    }
}
